package club325.webchat.database.hibernate.implement;

import java.util.List;

import org.hibernate.Query;

import club325.webchat.database.hibernate.dao.ComplainDAO;
import club325.webchat.database.hibernate.dao.HibernateUtil;
import club325.webchat.database.hibernate.domain.Complain;

public class ComplainImplement implements ComplainDAO
{

	public void saveComplain(Complain complain)
	{
		HibernateUtil.add(complain);
	}

	public void removeComplain(Complain complain)
	{
		HibernateUtil.delete(complain);
	}

	public Complain findComplainbyID(int id)
	{
		return (Complain) HibernateUtil.get(Complain.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<Complain> findComplainbyOwnerID(String OwnerID)
	{
		String HQL = "From Complain as complains WHERE complains.ownerID = ?";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		q.setString(0,OwnerID);
		return q.list();
	}

	@SuppressWarnings("unchecked")
	public List<Complain> getAllComplain()
	{
		String HQL = "From Complain as complains";
		Query q = HibernateUtil.getSession().createQuery(HQL);
		return q.list();
	}
}
